<template>
    <div class="newInfo-container">
        <h3>{{ newInfo.title }}</h3>
        <p>
            <span>发表时间:{{ newInfo.add_time | dataFormate }}</span>
            <span>点击{{ newInfo.click }}次</span>
        </p>
        <hr>
        <div v-html="newInfo.content"></div>
        <!-- 评论组件 -->
        <!-- 此处给子组件传的值不能是newInfo中的id
            因为文章详情和评论列表同时发送请求,会导致评论的请求拿不到id
         -->
        <com-box :id="id"></com-box>
    </div>
</template>
<script>
// 导入评论组件
import comment from '../subcomponents/comment.vue';
export default {
    data(){
        return {
            id:this.$route.params.id,
            newInfo:{}
        }
    },
    created(){
        this.getnewInfo();
    },
    methods:{
        getnewInfo(){
            this.$http.get('api/getnew/'+this.id).then(res=>{
                console.log(res);
                if(res.body.status==0){
                    this.newInfo = res.body.message[0];
                }
            })
        }
    },
    components:{
        'com-box':comment
    }
}
</script>
<style lang="scss" scoped>
    .newInfo-container {
        padding: 0 4px;
        h3 {
            font-size: 16px;
            text-align: center;
            margin: 15px 0;
            color: red;
        }
        p {
            display: flex;
            justify-content: space-between;
            font-size: 13px;
            color:#226aff;
        }
    }
</style>

